/*
 * Copyright 2013-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.openfeign;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;

/**
 * {@link FeignClient} and
 * {@link com.wl4g.infra.integration.feign.core.annotation.FeignConsumer} mutual
 * equivalence. </br>
 * Annotation for interfaces declaring that a REST client with that interface
 * should be created (e.g. for autowiring into another component). If ribbon is
 * available it will be used to load balance the backend requests, and the load
 * balancer can be configured using a <code>@RibbonClient</code> with the same
 * name (i.e. value) as the feign client.
 *
 * @author Spencer Gibb
 * @author Venil Noronha
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface FeignClient {

    /**
     * The name of the service with optional protocol prefix. Synonym for
     * {@link #name() name}. A name must be specified for all clients, whether
     * or not a url is provided. Can be specified as property key, eg:
     * ${propertyKey}.
     */
    @AliasFor("name")
    String value() default "";

    /**
     * The service id with optional protocol prefix. Synonym for {@link #value()
     * value}.
     *
     * @deprecated use {@link #name() name} instead
     */
    @Deprecated
    String serviceId() default "";

    /**
     * This will be used as the bean name instead of name if present, but will
     * not be used as a service id.
     * 
     * @return bean name instead of name if present
     * @since 3.0
     */
    String contextId() default "";

    /**
     * The service id with optional protocol prefix. Synonym for {@link #value()
     * value}.
     */
    @AliasFor("value")
    String name() default "";

    /**
     * Sets the <code>@Qualifier</code> value for the feign client.
     */
    @Deprecated
    String qualifier() default "";

    /**
     * @return the <code>@Qualifiers</code> value for the feign client.
     *
     *         If both {@link #qualifier()} and {@link #qualifiers()} are
     *         present, we will use the latter, unless the array returned by
     *         {@link #qualifiers()} is empty or only contains <code>null</code>
     *         or whitespace values, in which case we'll fall back first to
     *         {@link #qualifier()} and, if that's also not present, to the
     *         default = <code>contextId + "FeignClient"</code>.
     * @since 3.0
     */
    String[] qualifiers() default {};

    /**
     * An absolute URL or resolvable hostname (the protocol is optional).
     */
    String url() default "";

    /**
     * Whether 404s should be decoded instead of throwing FeignExceptions
     */
    boolean decode404() default false;

    /**
     * A custom <code>@Configuration</code> for the feign client. Can contain
     * override <code>@Bean</code> definition for the pieces that make up the
     * client, for instance {@link feign.codec.Decoder},
     * {@link feign.codec.Encoder}, {@link feign.Contract}.
     *
     * @see FeignClientsConfiguration for the defaults
     */
    Class<?>[] configuration() default {};

    /**
     * Fallback class for the specified Feign client interface. The fallback
     * class must implement the interface annotated by this annotation and be a
     * valid spring bean.
     */
    Class<?> fallback() default void.class;

    /**
     * Define a fallback factory for the specified Feign client interface. The
     * fallback factory must produce instances of fallback classes that
     * implement the interface annotated by {@link FeignClient}. The fallback
     * factory must be a valid spring bean.
     *
     * @see feign.hystrix.FallbackFactory for details.
     */
    Class<?> fallbackFactory() default void.class;

    /**
     * Path prefix to be used by all method-level mappings. Can be used with or
     * without <code>@RibbonClient</code>.
     */
    String path() default "";

    /**
     * Whether to mark the feign proxy as a primary bean. Defaults to false.
     */
    boolean primary() default true;

}
